<template>
  <div class="resume-preview-page">
    <div class="container">
      <!-- 页面标题 -->
      <div class="page-header">
        <h1 class="page-title">预览简历</h1>
        <div class="header-actions">
          <el-button @click="downloadResume">
            <el-icon><download /></el-icon>
            下载简历
          </el-button>
          <el-button type="primary" @click="editResume">
            <el-icon><edit /></el-icon>
            编辑简历
          </el-button>
        </div>
      </div>
      
      <!-- 简历预览内容 -->
      <div class="resume-preview" v-loading="loading">
        <template v-if="resume">
          <ResumePreviewContent :resume="resume" />
        </template>
        <el-empty v-else description="简历不存在或已被删除" />
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { Download, Edit } from '@element-plus/icons-vue'
import { getResumeDetail } from '@/api/resume'
import ResumePreviewContent from '@/components/resume/ResumePreviewContent.vue'

const route = useRoute()
const router = useRouter()

const loading = ref(false)
const resume = ref(null)

// 获取简历详情
const fetchResumeDetail = async () => {
  const id = route.params.id
  if (!id) {
    ElMessage.error('简历ID不能为空')
    return
  }
  
  loading.value = true
  try {
    const res = await getResumeDetail(id)
    if (res.code === 200) {
      resume.value = res.data
    } else {
      ElMessage.error(res.message || '获取简历详情失败')
    }
  } catch (error) {
    console.error('获取简历详情出错:', error)
    ElMessage.error('获取简历详情失败')
  } finally {
    loading.value = false
  }
}

// 下载简历
const downloadResume = async () => {
  try {
    // 实际应用中应该调用API
    // await resumeApi.downloadResume(route.params.id)
    
    ElMessage.success('简历下载中，请稍候')
  } catch (error) {
    console.error('下载简历失败', error)
    ElMessage.error('下载失败，请稍后再试')
  }
}

// 编辑简历
const editResume = () => {
  router.push(`/resumes/${route.params.id}/edit`)
}

// 初始化
onMounted(() => {
  fetchResumeDetail()
})
</script>

<style lang="scss" scoped>
@import '@/assets/styles/variables.css';

.resume-preview-page {
  padding: var(--spacing-xl) 0;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-xl);
  
  .page-title {
    font-size: 1.8rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
  }
  
  .header-actions {
    display: flex;
    gap: var(--spacing-md);
  }
}

.resume-preview {
  background: #fff;
  border-radius: var(--border-radius);
  padding: var(--spacing-xl);
  box-shadow: var(--box-shadow-sm);
}

// 响应式适配
@media (max-width: 768px) {
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    
    .page-title {
      margin-bottom: var(--spacing-md);
    }
    
    .header-actions {
      width: 100%;
      justify-content: flex-end;
    }
  }
}
</style> 